<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>破损维修单据查询</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript" src="/static/js/date.js"></script>
    <script type="text/javascript">

        var type;
        var url;
        //禁止整体该页面的右键弹出html相关,不阻碍easyui右键
        $(function () {

            $(document).bind('contextmenu', function (e) {
                e.preventDefault();
                $('#tree-0').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            });
        });
        $(document).ready(function () {

            var stype = $("#s_type").combobox("getValue");
            console.log("stype:" + stype);
            if (stype == 1) {
                $("#weixiuok").show();
            } else {
                $("#weixiuok").hide();
            }

            $("#s_type").combobox({
                onChange: function (n, o) {
                    var stype = $("#s_type").combobox("getValue");
                    console.log("stype:" + stype);
                    if (stype == 1) {
                        $("#weixiuok").show();
                    } else {
                        $("#weixiuok").hide();
                    }
                }
            });

            $("#s_btime").datebox("setValue", genLastMonthDayStr()); // 设置上个月日期
            $("#s_etime").datebox("setValue", genTodayStr()); // 设置当前日期

            $('#dg').datagrid({
                rowStyler: function (index, row) {
                    if (row.weixiuzhuangtai == "已修复") {
                        return 'background-color:GreenYellow;';
                        // color:blue;font-weight:bold;
                    }
                },
                onClickRow: function (index, row) {
                    if (type == 1) {

                        $("#dg2").datagrid({
                            url: '/admin/weixiudan/listDetailsByZId',
                            queryParams: {
                                zongzhangid: row.id
                            },
                            rowStyler: function (index, row) {
                                if (row.weixiuzhuangtai == "已修复") {
                                    return 'background-color:GreenYellow;';
                                    // color:blue;font-weight:bold;
                                }
                            },
                            onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                                e.preventDefault(); //阻止浏览器捕获右键事件
                                $(this).datagrid("clearSelections"); //取消所有选中项
                                $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                                $('#grid-data').menu('show', {
                                    left: e.pageX,//在鼠标点击处显示菜单
                                    top: e.pageY
                                });
                                e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                            },
                        });
                    } else if (type == 2) {
                        $("#dg2").datagrid({
                            url: '/admin/posundan/listDetailsByZId',
                            queryParams: {
                                zongzhangid: row.id
                            },
                            onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                                e.preventDefault(); //阻止浏览器捕获右键事件
                                $(this).datagrid("clearSelections"); //取消所有选中项
                                $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                                $('#grid-data').menu('show', {
                                    left: e.pageX,//在鼠标点击处显示菜单
                                    top: e.pageY
                                });
                                e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                            },
                        });
                    }

                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });

        });

        //维修OK
        function weixiuOk() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择已修复的维修单据！");
                return;
            }
            var selectDan = $("#s_type").combobox("getValue");
            console.log(selectDan);
            var path;
            if (selectDan == 1) {
                path = "weixiudan";
            } else if (selectDan == 2) {
                $.messager.alert("系统提示", "只能选择维修单据！");
                return;
            }
            var ids = new Array();
            if (selectedRows.length > 1) {
                for (var i = 0; i < selectedRows.length; i++) {
                    ids.push(selectedRows[i].id);
                }
            } else if (selectedRows.length == 1) {
                var id = selectedRows[0].id;
                ids.push(id);
            }

            var weixiuzhuangtai = selectedRows[0].weixiuzhuangtai;
            console.log("now:" + weixiuzhuangtai)
            if (weixiuzhuangtai == "已修复") {
                $.messager.confirm("系统提示", "<font color=red>当前状态为已修复,确定将更改至'未修复',库存将相应减少,是否操作？</font>", function (r) {
                    if (r) {
                        $.messager.confirm("系统提示", "<font color=blue>是否操作已修复->未修复？</font>", function (r) {
                            if (r) {
                                $.post("/admin/" + path + "/repair/" + weixiuzhuangtai, {'ids': ids}, function (result) {
                                    if (result.success) {
                                        $("#dg").datagrid("reload");
                                        $("#dg2").datagrid("reload");
                                    } else {
                                        $.messager.alert("系统提示", result.errorInfo);
                                    }
                                }, "json");
                            }
                        });

                    }
                })
            }else if(weixiuzhuangtai == "未修复"){
                $.messager.confirm("系统提示", "<font color=#5f9ea0>当前状态为未修复,确定将更改至'已修复',库存将相应增加,是否操作？</font>", function (r) {
                    if (r) {
                        $.messager.confirm("系统提示", "<font color=blue>是否操作未修复->已修复？</font>", function (r) {
                            if (r) {
                                $.post("/admin/" + path + "/repair/" + weixiuzhuangtai, {'ids': ids}, function (result) {
                                    if (result.success) {
                                        $("#dg").datagrid("reload");
                                        $("#dg2").datagrid("reload");
                                    } else {
                                        $.messager.alert("系统提示", result.errorInfo);
                                    }
                                }, "json");
                            }
                        });

                    }
                })
            }else{
                $.messager.alert("系统提示", "修复状态异常！");
                return;
            }
        }

        function search() {
            type = $("#s_type").combobox("getValue");
            var s_btime = $("#s_btime").datebox("getValue");
            var s_etime = $("#s_etime").datebox("getValue");
            $('#dg').datagrid('loadData', {total: 0, rows: []});
            $('#dg2').datagrid('loadData', {total: 0, rows: []});
            if (type == 1) {

                $('#dg').datagrid('showColumn', 'weixiudanhao');//列的field值
                $('#dg').datagrid('hideColumn', 'pusundanhao');//列的field值

                // var col = $('#dg').datagrid('getColumnOption','weixiudanhao');//获得该列属性
                // col.width = 90;//调整该列宽度
                // console.log(col)
                // col.align = 'center';

                $("#dg").datagrid({
                    url: '/admin/weixiudan/getSelective',
                    queryParams: {
                        // wuliaotuikudanhao:wuliaotuikudanhao,
                        // xiangmumingcheng:xiangmumingcheng,
                        // rukukufang:rukukufang,
                        weixiuzhuangtai:$("#x_type").combobox("getValue"),
                        s_btime: $("#s_btime").datebox("getValue"),
                        s_etime: $("#s_etime").datebox("getValue")
                    }
                });

            } else if (type == 2) {

                $('#dg').datagrid('showColumn', 'pusundanhao');//列的field值
                $('#dg').datagrid('hideColumn', 'weixiudanhao');//列的field值
                //
                // var col = $('#dg').datagrid('getColumnOption','pusundanhao');//获得该列属性
                // col.width = 90;//调整该列宽度
                // console.log(col)
                // col.align = 'center';

                $("#dg").datagrid({
                    url: '/admin/posundan/getSelective',
                    queryParams: {
                        // wuliaotuikudanhao:wuliaotuikudanhao,
                        // xiangmumingcheng:xiangmumingcheng,
                        // rukukufang:rukukufang,
                        s_btime: $("#s_btime").datebox("getValue"),
                        s_etime: $("#s_etime").datebox("getValue")
                    },
                    onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                        e.preventDefault(); //阻止浏览器捕获右键事件
                        $(this).datagrid("clearSelections"); //取消所有选中项
                        $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                        $('#grid-data').menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                        e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                    },
                });
            }
        }

        //删除维修单/破损单
        function deleteWeixiuOrPSdan() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择要删除的单据！");
                return;
            }
            var selectDan = $("#s_type").combobox("getValue");
            console.log(selectDan)
            var path;
            if (selectDan == 1) {
                path = "weixiudan";
            } else if (selectDan == 2) {
                path = "posundan";
            }
            var ids = new Array();
            if (selectedRows.length > 1) {
                for (var i = 0; i < selectedRows.length; i++) {
                    ids.push(selectedRows[i].id);
                }
            } else if (selectedRows.length == 1) {
                var id = selectedRows[0].id;
                ids.push(id);
            }
            $.messager.confirm("系统提示", "<font color=red>删除单据后,数据将返回库存,是否删除？</font>", function (r) {
                if (r) {
                    $.post("/admin/" + path + "/delete", {'ids': ids}, function (result) {
                        if (result.success) {
                            $("#dg").datagrid("reload");
                            $("#dg2").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    }, "json");
                }
            });
        }


    </script>
</head>
<body class="easyui-layout" style="margin: 1px">
<div region="north" style="height: 320px;">
    <table id="dg" title="破损维修查询" class="easyui-datagrid" fit="true"
           fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
           toolbar="#tb">
        <thead>
        <tr>
            <th field="id" width="30" align="center" sortable="true">编号</th>
            <th field="weixiudanhao" align="center" sortable="true">维修单号</th>
            <th field="pusundanhao" align="center" hidden="true" sortable="true">破损单号</th>
            <th field="weixiuzhuangtai" align="center" sortable="true">维修状态</th>
            <th field="xiangmumingcheng" width="30" align="center" sortable="true">项目名称</th>
            <th field="morenkufang" width="30" align="center" sortable="true">库房</th>
            <th field="chuangjianren" width="20" align="center" sortable="true">创建人</th>
            <th field="createtime" width="40" align="center" sortable="true">创建时间</th>
        </tr>
        </thead>
    </table>

    <div id="tb">
        <div style="padding-bottom: 5px">
            <fieldset style="border-color: #E7F0FF">
                <legend>查询设置</legend>
                &nbsp;&nbsp;&nbsp;查询日期：&nbsp;
                <input id="s_btime" class="easyui-datebox" editable=false style="width:100px">
                &nbsp;&nbsp;-&nbsp;&nbsp;
                <input id="s_etime" class="easyui-datebox" editable=false style="width:100px">
                &nbsp;&nbsp;&nbsp;单据类型：
                <select class="easyui-combobox" id="s_type" style="width: 100px;" editable="false" panelHeight="auto">
                    <option value="1">维修单</option>
                    <option value="2">破损单</option>
                </select>
                &nbsp;&nbsp;&nbsp;维修状态：
                <select class="easyui-combobox" id="x_type" style="width: 100px;" editable="false" panelHeight="auto">
                    <option value="">未选择</option>
                    <option value="未修复">未修复</option>
                    <option value="已修复">已修复</option>
                </select>
                <br>
                &nbsp;&nbsp;<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
                &nbsp;&nbsp;<a href="javascript:deleteWeixiuOrPSdan()" class="easyui-linkbutton" iconCls="icon-remove"
                               plain="true">删除</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:weixiuOk()" hidden="hidden" id="weixiuok"
                                                       class="easyui-linkbutton" iconCls="icon-ok" plain="true">已修复</a>
            </fieldset>
        </div>
    </div>
</div>
<div region="center" style="margin-top: 5px;">
    <table id="dg2" class="easyui-datagrid" fit=true
           fitColumns="true" pagination="true" rownumbers="true"
    >
        <!--toolbar="#tbzi">-->
        <thead>
        <tr>
            <th field="id" width="20" align="center" sortable="true">id</th>
            <th field="dalei" width="150" align="center" sortable="true">大类</th>
            <th field="wuliaobianma" width="50" align="center" sortable="true">物料编码</th>
            <th field="weixiuzhuangtai" align="center" sortable="true">维修状态</th>
            <th field="mingchengguige" width="50" align="center" sortable="true">名称规格</th>
            <th field="chukushuliang" width="50" align="center" sortable="true">报修/报损数量</th>
            <th field="danwei" width="50" align="center" sortable="true">单位</th>
            <th field="chukukufang" width="50" align="center" sortable="true">原库房</th>
            <th field="beizhu" width="50" align="center" sortable="true">备注</th>
            <th field="zongzhangid" width="50" align="center" hidden="true">zid</th>
        </tr>
        </thead>
    </table>

    <div id="tbzi">
        <div style="padding-bottom: 5px">
            <fieldset style="border-color: #E7F0FF">
                <legend>修复设置</legend>
                &nbsp;&nbsp;<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-ok"
                               plain="true">已修复</a>
                - 点击'已修复'选中物品返回原库存仓库
            </fieldset>
        </div>
    </div>
</div>

<!--大屏幕上右键datagrid dlg-->
<div id="grid-data" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="grid-data-edit" href="javascript:openDetailsModifyDialog()" data-options="iconCls:'icon-edit'">修改</div>-->
    <!--<div id="grid-data-delete" href="javascript:deleteDetails()" data-options="iconCls:'icon-remove'" plain="true">删除-->
    <!--</div>-->
</div>
<!--二级菜单右键弹出-->
<div id="tree-2" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-2-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除二级菜单</div>-->
</div>
<!--一级菜单右键弹出-->
<div id="tree-1" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-1-add-2" href="javascript:openTypeAddDialog()" data-options="iconCls:'icon-add'">添加二级菜单</div>-->
    <!--<div id="tree-1-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除一级菜单</div>-->
</div>
<!--树形菜单右键弹出-->
<div id="tree-0" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-0-add-1" href="javascript:openTypeAddDialog(0)" data-options="iconCls:'icon-add'">添加一级菜单</div>-->
    <!--<div id="tree-0-refresh" href="javascript:reloadTree()" data-options="iconCls:'icon-reload'">重新加载类别</div>-->
</div>

</body>
</html>